package gamecode;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class SpaceBackground {

	private List<EntityStar> stars;
	
	public SpaceBackground(int numStars, Rectangle bounds, EntityPlayerShip player) {
		stars = new ArrayList<EntityStar>();
		populateStars(numStars, bounds, player);
	}
	
	private void populateStars(int numStars, Rectangle bounds, EntityPlayerShip player) {
		Random rnd = new Random();
		rnd.setSeed(49737753);
		for(int i = 0; i < numStars; i++) {
			// randomize star color a bit
			int maxColor = 225;
			int c = rnd.nextInt(maxColor-50)+50;
			stars.add(new EntityStar(new Color(c + (rnd.nextInt(50)-25), c, c), new DPoint((rnd.nextDouble()*bounds.getWidth())+(player.getPosition().getX()-bounds.getWidth()/2), (rnd.nextDouble()*bounds.getHeight())+(player.getPosition().getY()-bounds.getHeight()/2))));
		}
	}
	
	public void drawStars(Graphics g, Rectangle bounds, EntityPlayerShip player) {
		for(EntityStar star : stars) {
			star.update(bounds, player);
			star.drawEntity(g, bounds, player);
		}
	}
}
